/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Juego;

import static java.lang.Thread.sleep;
import java.util.ArrayList;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author INGENIERIA
 */
public class HiloAsteroide extends Thread {
    int x,y;
  
    JLabel objeto;
    JLabel nave;
    JLabel boom;
    PanelImage jp;
    ArrayList<HiloDisparo>lista;
    
    public HiloAsteroide(JLabel objeto, int x,int y,JLabel nave,ArrayList<HiloDisparo>lista,PanelImage jp,JLabel tr){
        this.objeto=objeto;
        this.x=x;
        this.y=y;
        this.nave=nave;
        this.lista=lista;
        this.jp=jp;
        this.boom=tr;
   
    }

    
    
    public JLabel getObjeto() {
        return objeto;
    }

    public void setObjeto(JLabel objeto) {
        this.objeto = objeto;
    }


    public HiloAsteroide(){
    
    }
    
    
    @Override
    public void run(){
        HiloDisparo h=new HiloDisparo();
        int op=0;
        do{
        try{
            mover();
            sleep(100);
            if(nave.getBounds().intersects(objeto.getBounds())){
                
                nave.setVisible(false);
                objeto.setVisible(false);
                boom.setVisible(true);
                
                this.jp.add(boom);
                
                this.stop();
                

                
            }
            for(int i=0;i<lista.size();i++){
                if(objeto.getBounds().intersects(lista.get(i).getObjeto().getBounds())){
                    objeto.setVisible(false);
                    this.stop();
                }
            }
    
        }catch(InterruptedException e){
        
        }
        op++;
        }while(op<300);
    }
    public void mover(){
        y=y+2;
        objeto.setLocation(x, y);
    } 

    
    
    
    
    
}
